package com.polaris.live.widget

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import androidx.constraintlayout.widget.ConstraintLayout
import com.bumptech.glide.Glide
import com.polaris.live.databinding.WidgetListSubscriptBinding
import com.polaris.live.resp.back_resp.DisplayUserSymbolResp
import com.polaris.live.utils.image.ImageUtils
import com.zhpan.bannerview.annotation.Visibility

/**
 * 推荐角标
 *
 * @author Created by 半仙 on 2024/7/29/029 10:05
 */
class ListSubscriptView(context: Context, attributeSet: AttributeSet?) : ConstraintLayout(context, attributeSet) {

    private val mBinding = WidgetListSubscriptBinding.inflate(LayoutInflater.from(context), this, true)

    init {
        visibility = View.GONE
    }

    fun setUserSymbol(
        displayUserSymbolResp: DisplayUserSymbolResp? = null,
        maxLines: Int? = null,
        @Visibility showVis: Int? = null,
    ) {
        if (maxLines != null) {
            mBinding.tvSubscriptNickName.maxEms = maxLines
        }

        visibility = if (displayUserSymbolResp == null) {
            if (showVis != null) {
                showVis
            } else {
                View.GONE
            }
        } else {
            Glide.with(context).load(ImageUtils.imgPath(displayUserSymbolResp.icon)).into(mBinding.ivSubscriptIcon)
            mBinding.tvSubscriptNickName.text = displayUserSymbolResp.content
            when (displayUserSymbolResp.type) {
                REC -> mBinding.tvType.text = "Rec"
                else -> mBinding.tvType.text = ""
            }
            View.VISIBLE
        }
    }

    companion object {

        const val REC = 1
    }
}